package dry.example.intercept;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author zc
 */
@Slf4j
@Aspect
//@Component
public class DemoInterceptor {

    public static final String POINT_CUT = "execution(* dry.example.controller.*.*(..))";

    @Pointcut(POINT_CUT)
    public void operate() {
    }

    @Around("operate()")
    public Object operateDo(ProceedingJoinPoint p) throws Throwable {
        Signature signature = p.getSignature();
        String fullClassName = signature.getDeclaringTypeName();
        String methodName = signature.getName();
        Object[] parameter = p.getArgs();
        System.out.printf("fullClassName=%s methodName=%s parameter=%s%n", fullClassName, methodName, JSONObject.toJSONString(parameter));
        return p.proceed();
    }

}
